Test-Series - programming logic

Test Number 6/15

Q: What will be the output of the following code :

 main()

{

int i=10;

i=!i>14;

Printf ("i=%d",i);


}
A. i=0
B. Runtime Error
C. i=10
D. compile time error
Solution: The correct answer is:
i=0
Q: What will be the output of the following code :


main()
{
 extern i;
 printf("%d
",i);
 {
 int i=20;
 printf("%d
",i);
 }
}
A. Linked Error
B. No output
C. Runtime Error
D. 1
Solution: The correct answer is:
Linked Error
Q: What will be the output of the following code:

//assume all header files are included

main()
{
 float i=1.5;
 switch(i)
 {
case 1: printf("1");
case 2: print("2");
default : printf("0");
 }
}
A. 1
B. Runtime Error
C. No output
D. compiler error
Solution: The correct answer is:
compiler error
Q: What will be the output of the following code :

// assume all header files are included

main()
{
  int c=- -2;
printf("c=%d",c);
}
A. c=-2;
B. c=2;
C. Runtime Error
D. c=++2;
Solution: The correct answer is:
c=2;
Q: What will be the output of the following C code?

#include < stdio.h >

int x:
void main()
{
if (x)
print("hi");
else
printf("how are u");
}
A. hi
B. how are you
C. compile time error
D. error
Solution: The correct answer is:
how are you
Q: What will be the output of the following C code?

#include< stdio.h >
void main()
{
 int x=5;
if (x<1)
printf("hello");
if(x==5)
printf("hi");
else
printf("no");
}
A. hello
B. no
C. hi
D. error
Solution: The correct answer is:
hi
Q: What will be the output of the following code :


#include < stdio.h >
main()
 {
 const int i=4;
 float j;
 j = ++i;
 printf("%d %f", i,++j);
 } 
A. Runtime Error
B. 89
C. y
D. compile time error
Solution: The correct answer is:
Runtime Error
Q: What will be the output of the following code :



int i,j;
 for(i=0;i<=10;i++)
 {
 j+=5;
 assert(i<5);
 } 
A. 0
B. 89
C. Runtime Error
D. compile time error
Solution: The correct answer is:
 Runtime Error
Q: What will be the output of the following code :

//assume all header files are included

main()
{
int *ptr;
ptr=(int*)malloc(sizeof(int));
*ptr=200;
printf("the value of allocated object in %d",*ptr);
}
A. The value of allocated object is 200
B. Compilation Error
C. None of these
D. 200
Solution: The correct answer is:
The value of allocated object is 200
Q: What will be the output of the following code?

#include < stdio.h >
void main()
{
int x=5;
if(true);
printf("hello");
}
A. Compiler dependent
B.  It will throw an error
C. Nothing will be displayed
D. It will display hello
Solution: The correct answer is:
It will throw an error

You Have Score    /10